import React, { Component } from 'react';

import DefaultLoadingElement from 'lib/util/defaultLoadingElement.jsx'
import DefaultNoDataElement from 'lib/util/defaultNoDataElement.jsx'
import DefaultErrorElement from 'lib/util/defaultErrorElement.jsx'

export default class Loading extends Component {
  renderLoading() {
    return (<DefaultLoadingElement height={ this.props.height } style={ this.props.defaultStyle } />);
  }

  renderError() {
    return (<DefaultErrorElement height={ this.props.height } style={ this.props.defaultStyle } />);
  } // renderError

  renderNoData() {
    return (<DefaultNoDataElement height={ this.props.height } style={ this.props.defaultStyle } />);
  } // renderNoData

  renderBody(data) {
    return (
      <div>重写该方法</div>
    );
  } // renderBody

  render() {
    if (this.props.store.loading) {
      return this.renderLoading();
    } else if (this.props.store.error) {
      return this.renderError();
    } else if (this.props.store.data) {
      if (!this.props.noData) {
        return this.renderBody(this.props.store.data);
      } else {
        if (this.props.noData(this.props.store)) {
          return this.renderNoData();
        } else {
          return this.renderBody(this.props.store.data);
        }
      }
    } else {
      return null;
    }
  } // render
}

Loading.defaultProps = {
  store: {},
  noData: null,
  height: 200,
  defaultStyle: {}
}
